package com.javabaas.server.novel_server.cats.service;

import com.javabaas.server.novel_server.cats.entity.Cats;
import com.javabaas.server.novel_server.cats.entity.CatsRepository;
import com.javabaas.server.novel_server.common.ModuleCode;
import com.javabaas.server.novel_server.common.ResponseJson;
import com.javabaas.server.novel_server.common.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CatService {

    @Autowired
    CatsRepository repository;

    public Object cats() {
        List<Cats> cats = repository.findAll();

        List<Cats> males = new ArrayList<>();
        List<Cats> females = new ArrayList<>();
        List<Cats> press = new ArrayList<>();
        for (Cats c: cats) {
            if (c.getGender().equals("male")) {
                males.add(c);
            }else if (c.getGender().equals("female")) {
                females.add(c);
            }else if (c.getGender().equals("press")) {
                press.add(c);
            }
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("male", males);
        map.put("female", females);
        map.put("press", press);
        return ResponseJson.getResponseJson(ModuleCode.MODULE_CATS, StatusCode.STATUS_OK, map);
    }
}
